package com.bw.module_notice.view

import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.baway.notice.viewmodel.NoticeViewModel
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmFragment
import com.bw.module_notice.R
import com.bw.module_notice.adapter.NoticeAdapter
import com.bw.module_notice.databinding.FragmentNoticeBinding

@Route(path = RouterPath.PATH_FRAGMENT_NOTICE)
class NoticeFragment : BaseMvvmFragment<FragmentNoticeBinding>() {

    private val vm by lazy { ViewModelProvider(this)[NoticeViewModel::class.java] }
    private val noticeAdapter: NoticeAdapter = NoticeAdapter()

    override fun observeDataChange() {
    }

    override fun initViews() {
        super.initViews()
        mDataBinding.noticeRv.adapter = noticeAdapter
        mDataBinding.noticeRv.layoutManager = LinearLayoutManager(requireContext())
        vm.getNoticeList(0,30)
    }

    override fun loadData() {
        super.loadData()
        vm.mSuccessLiveData.observe(this){
            noticeAdapter.data.addAll(   it.filter { it.title=="社区活动"||it.title=="安全提醒"||it.title=="环境维护" })
            noticeAdapter.notifyDataSetChanged()
        }
    }

    override fun getLayoutId(): Int =R.layout.fragment_notice

}